package vista;

import java.awt.Color;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

import controlador.Controlador;
import modelo.dao.DAO;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class PanelModSalon extends JPanel {

	private DAO dao;
	private Controlador controlador;
	private JPanel actual;
	private JTextField textField;

	/**
	 * Create the panel.
	 * @param p 
	 */
	public PanelModSalon(DAO d, Controlador c, final JPanel p) {
		setBackground(Color.GRAY);
		setLayout(null);
		setSize(423,250);
		this.dao = d;
		this.controlador = c;
		this.actual = this;
		
		JButton btnAceptar = new JButton("Aceptar");
		btnAceptar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int valor=0;
				try{
					valor=Integer.parseInt(textField.getText());
				}catch(NumberFormatException ex){
					JOptionPane.showMessageDialog(actual, "Introduzca una cifra correcta");
				}
				p.removeAll();
				p.repaint();
				for (int i=0;i<valor;i++){
					FrameSalonMesaLibre panel=new FrameSalonMesaLibre();
					p.setLayout(new GridLayout(0,5));
					p.setBounds(10, 10, 782, 404);
					p.add(panel);
				}
				JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(actual);
				topFrame.dispose();
			}
		});
		btnAceptar.setBounds(49, 187, 100, 23);
		add(btnAceptar);
		
		JButton btnCancelar = new JButton("Cancelar");
		btnCancelar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(actual);
				topFrame.dispose();

			}
		});
		btnCancelar.setBounds(277, 187, 100, 23);
		add(btnCancelar);
		
		JLabel lblNMesas = new JLabel("Numero de Mesas:");
		lblNMesas.setBounds(49, 48, 114, 14);
		add(lblNMesas);
		
		textField = new JTextField();
		textField.setBounds(173, 45, 204, 20);
		add(textField);
		textField.setColumns(10);
	}

}
